package com.aiwu;

import android.os.Environment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.aiwu.library.abs.AbsArchiveManager;

import org.citra.citra_emu.CitraApplication;
import org.citra.citra_emu.utils.DirectoryInitialization;

import java.text.DecimalFormat;

public class ArchiveManger extends AbsArchiveManager {
    private volatile static ArchiveManger instance;

    public static ArchiveManger getInstance() {
        if (instance == null) {
            synchronized (ArchiveManger.class) {
                if (instance == null) {
                    instance = new ArchiveManger();
                }
            }
        }
        return instance;
    }

    private ArchiveManger() {
    }

    @Override
    public boolean dialogPauseSimulator() {
        return false;
    }

    @NonNull
    @Override
    protected String archiveFileNameRegex() {
        return makeQueryStringAllRegExp(CitraApplication.getRomName()) + ".([0-9]+).cst";
    }

    @NonNull
    @Override
    protected String getArchiveDir() {
        String userDirectory;
        if (DirectoryInitialization.getUserDirectory() != null) {
            userDirectory = DirectoryInitialization.getUserDirectory();
        } else {
            userDirectory = Environment.getExternalStorageDirectory().getAbsolutePath() + "/citra-emu";
        }
        return userDirectory+ "/states/";
    }

    @NonNull
    @Override
    protected String getArchiveFileName(int id) {
        DecimalFormat decimalFormat = new DecimalFormat("00");
        String slot = decimalFormat.format(id);
        return CitraApplication.getRomName() + "." + slot + ".cst";
    }

    @Nullable
    @Override
    protected String getArchivePicFileName(int id) {
        return CitraApplication.getRomName() + "_" + id + ".png";
    }
}
